﻿// Autore: Mattia Barrasso

using RecipesManager.Data;
using White.Core;
using White.Core.UIItems;
using White.Core.UIItems.ListBoxItems;
using White.Core.UIItems.WindowItems;

namespace RecipesManager.Specs.Categoria
{
    public class CategorieBDD
    {
        protected readonly string CategoryManagerTitle = "Gestione Categorie";
        protected Window MainWindow;
        protected Application Application;

        protected Button _newCategory;
        protected Button _backToMainMenu;
        protected ListBox _categories;

        protected TextBox _categoryName;

        protected ComboBox _superCategories;
        protected ListBox _selectedSuperCategories;
        protected Button _addSuperCategory;
        protected Button _removeSuperCategory;

        protected ComboBox _subCategories;
        protected ListBox _selectedSubCategories;
        protected Button _addSubCategory;
        protected Button _removeSubCategory;

        protected ListBox _linkedIngredients;
        protected Button _saveCategory;
        protected Button _closeSingleCategoryUi;

        protected void GetCategoriesUi()
        {
            _newCategory = MainWindow.Get<Button>("bt_add");
            _categories = MainWindow.Get<ListBox>("lb_items");
            _backToMainMenu = MainWindow.Get<Button>("bt_back");
        }

        protected void GetSingleCategoryUi()
        {
            _categoryName = MainWindow.Get<TextBox>("tb_nomeCategoria");

            _superCategories = MainWindow.Get<ComboBox>("cb_catSup");
            _selectedSuperCategories = MainWindow.Get<ListBox>("grid_cat_sup");
            _addSuperCategory = MainWindow.Get<Button>("agg_button_sup");
            _removeSuperCategory = MainWindow.Get<Button>("canc_button_sup");

            _subCategories = MainWindow.Get<ComboBox>("cb_catInf");
            _selectedSubCategories = MainWindow.Get<ListBox>("grid_cat_inf");
            _addSubCategory = MainWindow.Get<Button>("agg_button_inf");
            _removeSubCategory = MainWindow.Get<Button>("canc_button_inf");

            _linkedIngredients = MainWindow.Get<ListBox>("grid_ingred");

            _saveCategory = MainWindow.Get<Button>("save_button");
            _closeSingleCategoryUi = MainWindow.Get<Button>("close_button");
        }

        protected void SetUpScenario()
        {
            Manager.ClearDatabase();
            Manager.Measures.Add("grammi", "gr", MeasureType.Weight, MeasureFamily.Metric, 1);
            Manager.Measures.Add("PesoTest", "PT", MeasureType.Weight, MeasureFamily.Metric, 1);
            Application = Application.Launch(@"..\..\..\RecipesManager\bin\x86\WhiteTesting\RecipesManager.exe");
            MainWindow = Application.GetWindow("Recipes Manager");
        }

        
        protected void TearDownScenario()
        {
            Manager.ClearCache();
            Manager.ClearDatabase();
            Application.Kill();
        }

        protected void NavigateToCategories()
        {
            MainWindow.Get<Button>("categorie").Click();
            MainWindow = Application.GetWindow(CategoryManagerTitle);
        }

        protected void NavigateToMainMenu()
        {
            MainWindow.Get<Button>("bt_back").Click();
            MainWindow = Application.GetWindow("Recipes Manager");
        }
    }
}
